package ewa

import (
	linklist "container/list"
)

type Attr struct {
	Restrict bool
	SyncAck bool
	Queue string
}

type ROUTE struct{
	NRPage  string  //Non-Restrict Page
	RPage  string  	//Restrict Page
	CtrlEvent  string  //Control events
	NRApi  string 	//Non-Restrict Api
	RApi  string 	//Restrict Api
	ApiAttr string  //Api attributions

	ApiLogin string  // User login Api
	ApiAddUser string
	ApiChangePass string
	L_NRPage []string //Non-Restrict Page list
	L_RPage []string  //Restrict Page list
	L_CtrlEvent []string  //Control events list
	L_NRApi []string  //Non-Restrict Api list
	L_RApi []string   //Restrict Api list
	L_ApiAttr []string
	MApiAttr map[string]Attr  		
}

type Resource struct {
	HttpRoute string
	RealLocation string
}
type ECHO_Static struct{
	Config  string   // Original configuration- string
	L_Static []string   	// array
	ResList *linklist.List
}


type URL struct{
	Page  string //Page URI
	Static  string //Static resource: pic1.jpg, pic2.jpg
	L_Page []string
	L_Static []string
}

type RENDPAGE struct {
	PageSource string
	PageTempDir string
}

type AUTH struct {
	SL3File string
	SL3Table string
}

type REDISQ struct {
	Address string
	Password string
	ApiBind string
	MApiBind map[string]string
}

type LOGOPTION struct {
	Echorequest string
	Mysqlquery string
	Apichain string
}

/* Golbal Variables. */
var (
	EchoPort  string
	StaticRes ECHO_Static
	ExeDir string
	CfgRoute ROUTE
	CfgUrl  URL
	CfgRendPage RENDPAGE
	CfgAuth AUTH
	CfgRedisQ REDISQ
	RedisConnArgs_ RedisConnArgs
	MysqlConnArgs_ MysqlConnArgs
	Logoption LOGOPTION
)

func _RedisConnArgs_() {
	RedisConnArgs_ = RedisConnArgs {
	  Qname: "",
	  Network: "tcp",
	  Address: CfgRedisQ.Address,
	  Password: CfgRedisQ.Password,
	}
}

func MapKeys(m map[string]string) []string {
  // 数组默认长度为map长度,后面append时,不需要重新申请内存和拷贝,效率较高
  j := 0
  keys := make([]string, len(m))
  for k := range m {
    keys[j] = k
    j++
  }
  return keys
}

func MapAttrKeys(m map[string]Attr) []string {
  j := 0
  keys := make([]string, len(m))
  for k := range m {
    keys[j] = k
    j++
  }
  return keys
}

/*
func MapStaticResourceKeys(m map[string]ResFile) []string {
  j := 0
  keys := make([]string, len(m))
  for k := range m {
    keys[j] = k
    j++
  }
  return keys
}
*/